<?php
//控制器

class login extends mysql{
    function userlogin(){
        if(!empty($_POST)){
            $mysql = new mysql();
            $name = $_POST['username'];
            $pwd = $_POST['password'];
            $sql = 'select * from user_table where username ="'.$name.'"';
            $sql_q = $mysql->select_one($sql);
            if(!empty($sql_q)){
                if($sql_q['password'] == $pwd){
                    //session传值
                    $_SESSION = $sql_q;
                    if($sql_q['dd'] == 0){
                        $mysql->success(0,'index','home','userhome','登录成功，马上进入首页！');
                        /*header('Refresh: 0; url=home.php');*/
                        return 0;
                    }elseif($sql_q['dd'] == 9){
                        $mysql->success(1,'index','login','userlogin');
                        header('Refresh: 0; url=admin.php');
                        return 0;
                    }else{
                        echo '<script type="text/javascript">alert("此账号已被冻结！");</script>';
                    }
                }else{
                    echo '<script type="text/javascript">alert("账号或密码错误！");</script>';
                }
            }else{
                echo '<script type="text/javascript">alert("账号或密码错误！");</script>';
            }
        }


        $this->display('index','index','login',['url' => $this->config,'host' => $this->host]);
    }

}